﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Core.Services;
using MvcEngine.Core.Localization;

using MvcEngine.Core.Account;

namespace MvcEngine.Core.Helpers
{
    public class EmailHelper : IEmailHelper
    {
        protected EmailSettings settings = null;

        public static IEmailHelper Current
        {
            get { return IoC.Resolve<IEmailHelper>(); }
        }

        public EmailHelper()
        {
            settings = IoC.Resolve<IEmailService>("EmailService").GetSettings();
        }

        #region IEmailHelper Members

        public virtual void SendNotificationMessage(User user, string activateLink)
        {
            Guard.ThrowIfNull(user, "user");
            Guard.ThrowIfEmptyString(activateLink, "activateLink");

            string body = EmailSender.Current.GetMailBody("MailActivateUserTemplate", "userName", user.Name, "url", activateLink);
            EmailSender.Current.SendMailAsync(settings, settings.Email, user.Email, ResourceReader.Current.GetString("MailActivateUserTitle"), body);
        }

        public virtual void SendRestorePasswordLink(User user, string restoreLink)
        {
            Guard.ThrowIfNull(user, "user");
            Guard.ThrowIfEmptyString(restoreLink, "restoreLink");

            string body = EmailSender.Current.GetMailBody("MailForgotPasswordUserTemplate", "userName", user.Name, "url", restoreLink);
            EmailSender.Current.SendMailAsync(settings, settings.Email, user.Email, ResourceReader.Current.GetString("MailForgotPasswordUserTitle"), body);
        }
        #endregion
    }
}
